package com.example.adminvue.controller;

import com.example.adminvue.domain.*;
import com.example.adminvue.service.ISysMenuService;
import com.example.adminvue.service.LoginService;
import com.example.adminvue.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @Autowired
    private ISysMenuService menuService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginVO loginVO){
        User user = new User();
        user.setUserName(loginVO.getUsername());
        user.setPassword(loginVO.getPassword());
        return loginService.login(user);
    }

    @GetMapping("getRouters")
    public AjaxResult getRouters()
    {
        Long userId = SecurityUtils.getUserId();
        List<Menu> menus = menuService.selectMenuTreeByUserId(userId);
        return AjaxResult.success(menuService.buildMenus(menus));
    }


}
